<?php

require_once 'models/DAL/WPPOstsDAO.php';

class Application_Model_DbTable_WPPOsts extends Zend_Db_Table_Abstract {

    protected $_name = 'wp_posts';
    protected $_primary = 'ID';

//    "SELECT post_date, post_content, post_title, guid 
//        FROM wp_posts 
//        WHERE post_status = 'publish' 
//        AND post_type = 'post' 
//        ORDER BY post_date 
//        DESC LIMIT 0, 2"

    public function getSomePosts() {

        $return = array();

        $select = $this
                ->select()
                ->from($this->_name, array('post_date', 'post_content', 'post_title', 'guid'))
                ->where("post_status = 'publish'")
                ->where("post_type = 'post'")
                ->order(array('desc' => 'post_date'))
                ->limit(4);
        $rows = $this->fetchAll($select)->toArray();

        foreach ($rows as $row) {

            $dao = new Application_Model_DAO_WPPOsts();

            $dao->setPostDate($row['post_date']);
            $dao->setPostContent($row['post_content']);
            $dao->setPostTitle($row['post_title']);
            $dao->setGuid($row['guid']);

            $return[] = $dao;
        }
        return $return;
    }

}

